package com.inibb.app.util.upload;

import java.io.File;
import java.util.Properties;

public class FileNameValidationHandler implements FileHandler{
	private Properties fileConfig;
	
	public FileNameValidationHandler(Properties fileConfig){
		super();
		this.fileConfig=fileConfig;
	}
	
	public ValidationResult handle(File file) {
		int fileNameLength=Integer.parseInt(fileConfig.getProperty("system.upload.fileNameLength"));
		ValidationResult vr=new ValidationResult();
		if(file.getName().length()>fileNameLength){
			vr.getErrors().put(file.getName(), "The file'name is too long");
		}
		return vr;
	}
	
	
	public static void main(String[] args) {
		File file=new File("d:/fileupload.properties");
		Properties config=new Properties();
		config.setProperty("system.upload.fileNameLength", "15");
		ValidationResult result=new FileNameValidationHandler(config).handle(file);
		System.out.println(result.getErrors().get(file.getName()));
	}
}
